import { DescItem } from '/@/components/Description';
import { BasicColumn } from '/@/components/Table/src/types/table';

export const objectSchema: DescItem[] = [
  {
    field: 'id',
    label: 'ID',
  },
  {
    field: 'nickname',
    label: '机器名称',
  },
  {
    field: 'public_address',
    label: '公网地址',
  },
  {
    field: 'local_address',
    label: '内网地址',
  },
  {
    field: 'report_interval',
    label: '上报粒度',
    render: (num: number) => num + ' 秒',
  },
  {
    field: 'resend_times',
    label: '重发次数',
    render: (num: number) => num + ' 次',
  },
  {
    field: 'fetch_timeout',
    label: '抓取超时',
    render: (num: number) => num + ' 秒',
  },
];

export const ownerTableSchema: BasicColumn[] = [
  {
    title: '用户ID',
    width: 100,
    dataIndex: 'id',
    fixed: 'left',
  },
  {
    title: '用户名称',
    width: 150,
    dataIndex: 'username',
  },
  {
    title: '用户邮箱地址',
    width: 150,
    dataIndex: 'email',
  },
];
export const ruleToObjectSchema: BasicColumn[] = [
  {
    title: '规则ID',
    width: 100,
    dataIndex: 'id',
    fixed: 'left',
  },
  // todo: 弄按钮组
  // 参考: https://antdv.com/components/button-cn
  {
    title: '启用情况',
    width: 75,
    dataIndex: 'is_enable',
    customRender: ({ text }) => {
      if (text === 'true') {
        return <a-button color={'success'}> 启用 </a-button>;
      } else {
        return <a-button color={'error'}> 停用 </a-button>;
      }
    },
  },
  {
    title: '指标',
    width: 150,
    dataIndex: 'metric',
  },
  {
    title: '名称',
    width: 150,
    dataIndex: 'nickname',
  },
  {
    title: '数值范围	',
    width: 150,
    dataIndex: 'range',
  },
  {
    title: '告警级别',
    width: 150,
    dataIndex: 'alarm_level',
  },
];

export const settingToObjectSchema: BasicColumn[] = [
  {
    title: '聚合ID',
    width: 100,
    dataIndex: 'id',
    fixed: 'left',
  },
  {
    title: '启用情况',
    width: 75,
    dataIndex: 'is_enable',
    customRender: ({ text }) => {
      if (text === 'true') {
        return <a-button color={'success'}> 启用 </a-button>;
      } else {
        return <a-button color={'error'}> 停用 </a-button>;
      }
    },
  },
  {
    title: '指标	',
    width: 150,
    dataIndex: 'metric',
  },
  {
    title: '名称',
    width: 150,
    dataIndex: 'nickname',
  },
  {
    title: '时间长度',
    width: 150,
    dataIndex: 'length',
    customRender: ({ text = 0 }) => {
      return text && text + ' 分钟';
    },
  },
  {
    title: '聚合方法',
    width: 150,
    dataIndex: 'method',
  },
];
